package echat.future.cn.echat.message.rank;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import echat.future.cn.echat.R;
import lumingweihua.future.cn.baselibgxh.base.BaseActivity;

/**
 * Created by JX on 2018/8/18.
 */

public class RankActivity extends BaseActivity {

    private ViewPager mViewPager;
    private TextView tv_xiannv;
    private TextView tv_tuhao;

    @Override
    public void initView() {
        setContentView(R.layout.activity_rank);

        tv_xiannv = findViewById(R.id.tv_xiannv);
        tv_tuhao = findViewById(R.id.tv_tuhao);

        tv_xiannv.setOnClickListener(this);
        tv_tuhao.setOnClickListener(this);
        findViewById(R.id.iv_back).setOnClickListener(this);

        mViewPager = findViewById(R.id.viewPager);
        mViewPager.setAdapter(new MyAdapter(getSupportFragmentManager()));
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void processClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.tv_xiannv:
                mViewPager.setCurrentItem(0);
                tv_xiannv.setBackgroundResource(R.drawable.rank_selected_bg);
                tv_tuhao.setBackgroundResource(0);
                break;
            case R.id.tv_tuhao:
                mViewPager.setCurrentItem(1);
                tv_xiannv.setBackgroundResource(0);
                tv_tuhao.setBackgroundResource(R.drawable.rank_selected_bg);
                break;
        }
    }

    private class MyAdapter extends FragmentPagerAdapter {

        private RankFragment xiannvFragment;
        private RankFragment tuhaoFragment;

        public MyAdapter(FragmentManager fm) {
            super(fm);
            xiannvFragment = RankFragment.newInstance(1);
            tuhaoFragment = RankFragment.newInstance(2);
        }

        @Override
        public Fragment getItem(int position) {
            if (position == 0) {
                return xiannvFragment;
            }
            return tuhaoFragment;
        }

        @Override
        public int getCount() {
            return 2;
        }
    }

}